package com.xjl.everyinterview.datastructureandalgorithm.algorithm.sort.Bubble;

/**
 * @author xjl
 * @version 1.0
 * @description: 分析  循环的思想
 * 1 O(n^2)
 * 2 对比前后两个 交换
 * @date 2021/8/18 18:25
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {5, 8, 6, 3, 9, 2, 1, 7};

        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                int tmp = 0;
                if (arr[j] > arr[j + 1]) {
                    tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                }
            }
        }

        System.out.println(String.valueOf(arr));
    }

}
